<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Default_Model_ProcessFaculty extends ZF_DB{
    protected $_table_name = "process_to_faculty" ;
    protected $_table_rate = "rate";
    
    protected $_id;
    protected $_id_hospital;
    protected $_id_faculty;
    protected $_description;
    protected $_rate;
    protected $_counter;
    
    public function getIdHospital(){
        return $this->_id_hospital;
    }
    public function setIdHospital($idHospital){
        $this->_id_hospital = $idHospital;
    }
    public function getIdFaculty(){
        return $this->_id_faculty;
    }
    public function setIdFaculty($idFaculty){
        $this->_id_faculty = $idFaculty;
    }
    public function getDescription(){
        return $this->_description;
        
    }
    public function setDescription($description){
        $this->_description = $description;
    }
    public function getRate(){
        return $this->_rate;
    }
    public function setRate($rate){
        $this->_rate = $rate;
    }
    public function getCounter(){
        return $this->_counter;
    }
    public function setCounter($counter){
        $this->_counter = $counter;
    }
    
    public function insert($name,$idHospital,
            $idFaculty, $description,
            $rate, $counter){
        
        if($name && $idHospital && $idFaculty && $description
                && $rate && $counter){             
                $data =  array(
                    'name' =>$name,
                    'id_hospital'=>$idHospital,
                    'id_faculty' =>$idFaculty,
                    'is_description'=>$description,
                    'rate'=>$rate,
                    'counter'=>$counter);
            return         $this->db->insert($this->_table_name,$data);
	
	}
        return -1;
	
    }
   
    public function update(){
        $where  = "id = $this->_id";
	$data =  array(
                    'name' =>$this->_name,
                    'id_hospital'=>$this->_id_hospital,
                    'id_faculty' =>$this->_id_faculty,
                    'description'=>$this->_description,
                    'rate'=>$this->_rate,
                    'counter'=>$this->_counter);
        
	return $this->db->update(
                $this->_table_name,
                $data,$where);
    }
    public function getById($id){
        if($id)
	{
		$select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.id = ?",$id );
		
		$data = $this->db->fetchRow($select);
		if($data){
			$this->_id = $data['id'];
			$this->_name = $data['name'];
			$this->_id_hospital = $data['id_hospital'];
			$this->_id_faculty = $data['id_faculty'];
                        $this->_description = $data['description'];       
                        $this->_rate = $data['rate'];
                        $this->_counter = $data['counter'];
                }
                return $data;
	}
	return -1;
    }
    
    public function getByIdHospitalFacultyRate($id_hospital, $id_faculty, $rate){
        if($rate)
	{
            if ($id_hospital != "-1" && $id_faculty != "-1") {
                $select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.id_hospital = ?", $id_hospital)
                        ->where("p.id_faculty = ?", $id_faculty)
                        ->where("p.rate >= ?", $rate)
                        ->order("p.rate DESC");
            } else if ($id_hospital != "-1") {
                $select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.id_hospital = ?", $id_hospital)
                        ->where("p.rate >= ?", $rate)
                        ->order("p.rate DESC");
            } else if ($id_faculty != "-1") {
                $select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.id_faculty = ?", $id_faculty)
                        ->where("p.rate >= ?", $rate)
                        ->order("p.rate DESC");
            } else {
                $select = $this->db->select()
			->from(array("p"=>$this->_table_name))
                        ->where("p.rate >= ?", $rate)
                        ->order("p.rate DESC");
            }
            $data = $this->db->fetchAll($select);
            return $data;
	}
	return -1;
    }
   
    public function listAll(){
        $select = $this->db->select()
                ->from($this->_table_name);
	$data = $this->db->fetchAll($select);
	return $data;
    }
}
?>
